/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farent.solutions.plugins.stripes.hyperstripes.core;

import com.farent.solutions.plugins.stripes.hyperstripes.core.tags.StandardHTMLTagHandler;
import com.farent.solutions.plugins.stripes.hyperstripes.spi.RenderKit;
import java.util.List;
import javax.xml.namespace.QName;

/**
 *
 * @author farouka
 */
public class ComponentTagHandlerFactory
{

    static
    {
        ComponentAnnotationProcessor.getInstance().startUp();
    }

    private ComponentTagHandlerFactory()
    {
    }

    public static ComponentTagHandlerFactory getInstance()
    {
        return ComponentTagHandlerHolder.INSTANCE;
    }

    public ComponentTagHandler getTagHandlerForTag( QName qName,
            StripesApplicationContext applicationContext )
    {
        String tagName = qName.getLocalPart();
        String namespace = qName.getNamespaceURI();
        RenderKit renderkit = applicationContext.getRenderKit( namespace );
        if( renderkit == null )
            renderkit = HyperStripesRenderKit.getInstance();
        ComponentTagHandler tagHandler = renderkit.getTagHandlerForTag(
                tagName );
        if( tagHandler == null )
        {
            tagHandler = new StandardHTMLTagHandler();
        }
        return tagHandler;
    }

    private static class ComponentTagHandlerHolder
    {

        private static final ComponentTagHandlerFactory INSTANCE =
                new ComponentTagHandlerFactory();
    }
}
